﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

namespace Gqq.Csharpindepth.Chapter1
{
    public class Product
    {
        #region 基本元素
        public int Id { get; private set; }
        public string Name { get; private set; }

        public int StorageId { get; set; }

        //构造函数
        public Product(int id = 0, string name = "", int storId = 0)
        {
            Id = id;
            Name = name;
            StorageId = storId;
        }


        #endregion

        #region 取得列表
        /// <summary>
        /// 取得泛型的列表
        /// </summary>
        /// <returns></returns>
        public static List<Product> GetSampleLists()
        {
            var lstProducts = new List<Product>
                                  {
                                      //这时候，必须要求Product类有默认的构造函数。
                                      new Product {Id = 5, Name = "qianbi", StorageId = 3},
                                      new Product {Id = 16, Name = "xiaodao", StorageId = 1},
                                      new Product {Id = 3, Name = "xiangpi", StorageId = 1}
                                  };
            return lstProducts;
        } 

        
        public static ArrayList GetSampleArrLists()
        {
// ReSharper disable SuggestUseVarKeywordEvident
            ArrayList lists = new ArrayList
                                  {
                                      new Product {Id = 5, Name = "111"},
                                      new Product {Id = 6, Name = "111e"},
                                      new Product {Id = 8, Name = "1112"},
                                      new Product {Id = 11, Name = "12311"}
                                  };
// ReSharper restore SuggestUseVarKeywordEvident
            return lists;
        }

        #endregion

        //用于输出product
        public static void Output(Product p)
        {
            Console.WriteLine(p);
        }

        public override string ToString()
        {
            return string.Format("Id:{0} Name:{1}", Id.ToString(CultureInfo.InvariantCulture), Name);
        }
    }
}
